package cn.hallele.leinsteining.ms.support.starter.context.impl;

import cn.hallele.leinsteining.mc.infrastructure.metadata.enums.ServiceEnum;
import cn.hallele.leinsteining.mc.infrastructure.metadata.io.Response;
import cn.hutool.extra.spring.SpringUtil;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.env.Environment;

/**
 * 微服务上下文
 *
 * @author anle5
 * @since 2024/7/27 0:38
 */
@Slf4j
@Getter
@Setter
public class MSContext extends LeInSteiningContext {
    private static final String APPLICATION_NAME_KEY = "spring.application.name";

    private static final Environment ENVIRONMENT = SpringUtil.getBean(Environment.class);

    /**
     * 当前微服务所处
     */
    private ServiceEnum service;

    /**
     * 执行结果
     */
    private Response<?> result;

    public static MSContext instance() {
        MSContext msContext = new MSContext();
        msContext.service = ServiceEnum.getServiceEnum(ENVIRONMENT.getProperty(APPLICATION_NAME_KEY));
        return msContext;
    }
}
